package com.zlx.guguanjia.controller;

import com.zlx.guguanjia.entity.Result;
import com.zlx.guguanjia.entity.SysResource;
import com.zlx.guguanjia.entity.SysResource;
import com.zlx.guguanjia.service.SysResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @ClassName SysResourceCtroller
 * @Description TODO
 * @Author Edward
 * @Date 2020/11/4 22:34
 */

@RestController
@RequestMapping("/manager/menu")
public class SysResourceCtroller {
    @Autowired
    private SysResourceService service;


    @GetMapping("")
    public Result getMenu(){
        SysResource resource = new SysResource();
        resource.setDelFlag("0");
        return new Result(service.select(resource));
    }
    //getResourceByRid()
    @GetMapping("getResourceByRid/{rid}")
    public Result getResourceByRid(@PathVariable("rid") Long rid){
        return new Result(service.selectResourceByRid(rid));
    }

    @GetMapping("getParentMenus")
    public Result getParentMenus(){
        return new Result(service.selectParentMenuSources());
    }

    @GetMapping("selectPage/{start}/{pageSize}")
    public Result getMenuResources(@PathVariable("start") Integer start, @PathVariable("pageSize") Integer pageSize, @RequestParam Map<String,Object> map){
        return new Result(service.selectMenuSources(start,pageSize,map));
    }

    @GetMapping("getAllParentMenus")
    public Result getAllParentMenus(){
        SysResource resource = new SysResource();
        resource.setDelFlag("0");
        resource.setParentId(0L);
        return new Result(service.select(resource));
    }

    @PutMapping("updateMenuById")
    public Result updateMenuById(@RequestBody SysResource resource){
        resource.setUpdateDate(new Date());
        return new Result(service.updateByPrimaryKeySelective(resource));
    }
    //逻辑删除
    @PutMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        SysResource resource = new SysResource();
        resource.setId(id);
        resource.setDelFlag("1");
        resource.setUpdateDate(new Date());
        //返回分页数据
        return new Result(true,"删除成功",service.updateByPrimaryKeySelective(resource));
    }
}
